import React, { Component } from 'react';
// 
import { connect } from 'react-redux';
import { addpushAction } from '../../store-modules/actions/shopActions'
class Shop extends Component {
    render() {
        const { addpush, shopReducer } = this.props;
        return (
            <div>
                <p>
                    <button onClick={() => {
                        // 添加商品
                        addpush({
                            id: 3,
                            proname: '外星人笔记本'
                        })
                    }}>添加笔记本</button>
                </p>
                <ul>
                    {
                        shopReducer.shopArr.map(item => {
                            return <li key={item.id}>{item.proname}</li>
                        })
                    }
                </ul>

            </div>
        )
    }
}

// 定义辅助函数
function mapsattetoprops(state) {
    return state
}

function mapDispatchToProps(dispatch) {
    return {
        addpush(payload) {
            // 派发任务
            dispatch(addpushAction(payload))
        }
    }
}

export default connect(mapsattetoprops, mapDispatchToProps)(Shop)




